﻿<Local:NavigationView
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    NavigationCacheMode="Enabled"    
    x:Class="SeriesManager.View.SubscriptionView"        
    xmlns:Local="using:SeriesManager.View"
    xmlns:Converter="using:SeriesManager.Converter">
    
    <Page.Resources>
        <Converter:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter" />
        <Converter:EnumVisibilityConverter x:Key="EnumVisibilityConverter" />
        
        <ItemsPanelTemplate x:Key="Landscape900SeasonTemplate">
            <VariableSizedWrapGrid ItemHeight="350" ItemWidth="238" />
        </ItemsPanelTemplate>
    </Page.Resources>

    <Grid>
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <GridView
            x:Name="gridView"
            Grid.RowSpan="2"
            Style="{StaticResource GridViewStyle}" 
            Padding="116,137,40,46"
            SelectionMode="Extended"
            Local:GridViewExtensions.BindableSelection="{Binding SelectedItems, Mode=TwoWay}"
            Local:EventToCommandBehavior.RoutedEvent="ItemClick"
            Local:EventToCommandBehavior.Command="{Binding ItemClickedCommand}"
            ItemsSource="{Binding View}">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid ItemHeight="279" ItemWidth="189" />
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Image Source="{Binding Poster.LocalPath, TargetNullValue=/Assets/ActorsViewPlaceholder.png}" Stretch="Fill" />
                        <TextBlock FontFamily="Segoe UI Symbol" Text="&#xE10B;" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,6,6" FontSize="26.667" Foreground="White" Visibility="{Binding State, Converter={StaticResource EnumVisibilityConverter}, ConverterParameter=TwoWay}"/>
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>

        <ListView
            x:Name="listView"
            Visibility="Collapsed"
            Style="{StaticResource ListViewStyle}"
            Grid.RowSpan="2"
            Padding="30,0"
            Margin="0,140,0,0"
            SelectionMode="Extended"
            Local:ListViewExtensions.BindableSelection="{Binding SelectedItems, Mode=TwoWay}"
            Local:EventToCommandBehavior.RoutedEvent="ItemClick"
            Local:EventToCommandBehavior.Command="{Binding ItemClickedCommand}"
            ItemsSource="{Binding View}">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Stretch">
                        <Image Source="{Binding Banner.LocalPath}" Stretch="Fill" />
                        <TextBlock FontFamily="Segoe UI Symbol" Text="&#xE10B;" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,6,6" FontSize="26.667" Foreground="White" Visibility="{Binding State, Converter={StaticResource EnumVisibilityConverter}, ConverterParameter=TwoWay}"/>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        
        <TextBlock x:Uid="NoSubscription" FontSize="28" TextWrapping="Wrap" Margin="116,20,60,40" Visibility="{Binding IsEmpty, Converter={StaticResource BooleanVisibilityConverter}}" Grid.Row="1" />

        <Grid x:Name="headerGrid" Margin="120,0,40,20">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="0,0,0,20">
                <TextBlock Text="&#xE113;" FontFamily="Segoe UI Symbol" FontSize="44" Margin="0,0,30,0" Style="{StaticResource HeaderTextBlockStyle}" IsHitTestVisible="False" />
                <TextBlock x:Uid="SubscriptionHeader" Style="{StaticResource HeaderTextBlockStyle}" IsHitTestVisible="false" TextWrapping="NoWrap" />
            </StackPanel>
        </Grid>

        <CommandBar IsOpen="{Binding NavigationBarIsOpen, Mode=TwoWay}" Grid.Row="1">
            <AppBarButton x:Uid="WatchedAppBarButton" Icon="Accept" Command="{Binding WatchStateCommand}" />
            <AppBarButton x:Uid="UnwatchedAppBarButton" Icon="Cancel" Command="{Binding UnwatchStateCommand}" />
            <AppBarButton x:Uid="DeleteAppBarButton" Icon="Delete" Command="{Binding UnSubscribeCommand}" />
            
            <CommandBar.SecondaryCommands>
                <AppBarButton x:Uid="SelectionClearAppBarButton" Icon="ClearSelection" Command="{Binding SelectionClearCommand}" />
                <AppBarButton x:Uid="SelectionAllAppBarButton" Icon="SelectAll" Command="{Binding SelectionAllCommand}" />
            </CommandBar.SecondaryCommands>
        </CommandBar>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="Landscape500">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="gridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="listView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="headerGrid" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="30,0,30,20"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Landscape768" />
                <VisualState x:Name="Landscape900">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="gridView" Storyboard.TargetProperty="ItemsPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource Landscape900SeasonTemplate}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Local:NavigationView>